import java.util.Arrays;

class Solution {
    public int triangleNumber(int[] nums) {
        Arrays.sort(nums);
        int big = nums.length - 1;
        int count = 0;
        while(big > 1) {
            int right = big - 1,left = 0;
            while(left < right) {
                if(nums[left] + nums[right] > nums[big]) {
                    count += (right - left);
                    right--;
                }else {
                    left++;
                }
            }
            big--;
        }
        return count;
    }
}